<?php

class Core_Model_User extends YouNet_Model_User
{
	/**
	 * Check if user is owner of a store
	 * @param Core_Model_Store $store
	 * @return boolean 
	 */
	public function isOwnerStore(Core_Model_Store $store)
	{
		return $store->id_user == $this->id;
	}
	
	/**
	 * Check if user is admin of a store
	 * @param Core_Model_Store $store
	 * @return boolean 
	 */
	public function isAdminOfStore(Core_Model_Store $store)
	{
		//@todo
		$socialPlugin = YouNet_Api::getInstance()->getSocialPlugin();
		$arrUserIdPages		= $socialPlugin->getUserPageIds();		
		$arrIdStorePages	= $store->getArrIdPages();
		$isValues			= false;
		foreach($arrIdStorePages as $idPage)
		{
			if( in_array($idPage, $arrUserIdPages) )
			{
				$isValues = true;
				break;
			}
		}
		return $isValues;
	}
	
	/**
	 * Check if user has permission (owner || admin) of a store
	 * @param Core_Model_Store $store
	 * @return type 
	 */
	public function hasPermissionWithStore(Core_Model_Store $store)
	{
		return $this->isOwnerStore($store) || $this->isAdminOfStore($store);
	}
}